{include file="common/header" /}
<link rel="stylesheet" href="__LAYUIMINI__/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<style>
    body {
        background-color: #ffffff;
    }
    .img-item {
        position: relative;
        width: 96px;
        height: 96px;
        border-radius: 6px;
        margin-bottom: 10px;
        margin-right: 10px;
    }
    .img-item img {
        border-radius: 6px;
        width: 100%;
        height: 100%;
    }
    .img-item i {
        font-size: 20px;
        position: absolute;
        top: -10px;
        right: -10px;
    }

</style>
<body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>模型操作</legend>
</fieldset>
<div class="layui-form layuimini-form">
        {if condition="input('param.id')"}
        <input type="hidden" name="id" value="{:input('param.id')}">
        {/if}
      <div class="layui-form-item">
        <label class="layui-form-label">模型名称</label>
        <div class="layui-input-block" style="width:500px;">
          <input type="text" class="layui-input field-title" lay-verify="required" name="title" autocomplete="off" placeholder="请输入模型名称" >
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">表名</label>
        <div class="layui-input-block" style="width:500px;">
          <input {if condition="isset($data_info)"}disabled{/if} type="text" class="layui-input field-name" lay-verify="required" name="name" autocomplete="off" placeholder="请输入表名" >
        </div>
      </div>
     
     <div class="layui-form-item layui-form-text">
        <label class="layui-form-label" style="width:610px;">描述</label>
        <div class="layui-input-block" style="width:610px;">
          <textarea name="description" placeholder="请输入描述" class="layui-textarea field-description"></textarea>
        </div>
      </div>
      
      {if condition="!isset($data_info)"}
      <div class="layui-form-item" >
        <label class="layui-form-label">新建表字段</label>
        <div class="layui-input-block" >
          <input type="radio" name="emptytable" value="0" title="基本表" checked="" class="field-emptytable">
          <input type="radio" name="emptytable" value="1" title="文章、图片表模型" class="field-emptytable">
          <input type="radio" name="emptytable" value="2" title="单页模型" class="field-emptytable">
        </div>
      </div>
      <div class="layui-form-item" >
        <label class="layui-form-label">所属类型</label>
        <div class="layui-input-block" >
          <input type="radio" name="type" value="0" title="栏目管理" checked="" class="field-type">
          <input type="radio" name="type" value="1" title="网站功能" class="field-type">
        </div>
      </div>
      {/if}
      
      
      
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="saveBtn">立即提交</button>
          <a href="{:url('index')}" class="layui-btn layui-btn-primary">返回</a>
        </div>
      </div>
</div>

<script>
    layui.use(['form','iconPickerFa','upload','laydate'], function () {
        var form = layui.form,
            iconPickerFa = layui.iconPickerFa,
            layer = layui.layer,
            upload = layui.upload,
            laydate = layui.laydate,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.load(1, {
                shade: [0.3,'#000'] //0.1透明度的白色背景
            });
            var data = data.field;
            // console.log(data)
            // return false
            $.ajax({
                url:"{:url('module/add')}",
                data:data,
                type:'post',
                dataType:'json',
                success:function(res){
                    // console.log(res)
                    // return false
                    if(res.errcode != 1){
                        layer.msg(res.message,{icon: 2,time: 2000},function(){
                            layer.close(index);
                        })
                    }else{
                        layer.msg(res.message,{icon: 1,time: 1000},function () {
                            window.location.href = "{:url('info/list')}";
                        })
                    }
                    layer.close(index);
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('网络失败，请刷新页面后重试!',{icon: 2,time: 2000})
                }
            });

            return false;
        });

    });
</script>
</body>

</html>